package com.cskaoyan.controller;

import com.cskaoyan.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author stone
 * @date 2022/10/06 09:35
 */
@Controller
@RequestMapping("account")
public class AccountController {

    @Autowired
    AccountService accountService;

    //@RequestMapping(value = "transfer",produces = "text/html;charset=utf-8")
    @RequestMapping(value = "transfer")
    @ResponseBody
    public String transfer(HttpServletRequest request, HttpServletResponse response) {
        //response.setContentType("text/html;charset=utf-8");
        // 做了这个设置，发现还是？？？？
        // 设置是否成功？成功
        // doDispatch中处理结果，StringHttpMessageConverter set iso-8859-1

        String fromId = request.getParameter("fromId");
        String destId = request.getParameter("destId");
        String money = request.getParameter("money");
        Integer fromIdInt = Integer.parseInt(fromId);
        Integer destIdInt = Integer.parseInt(destId);
        Integer moneyInt = Integer.parseInt(money);


        accountService.transfer(fromIdInt, destIdInt, moneyInt);
        /*Integer fromMoney = accountService.query(fromIdInt);
        Integer destMoney = accountService.query(destIdInt);


        accountService.modify(fromIdInt, (fromMoney - moneyInt));
        accountService.modify(destIdInt, (destMoney - moneyInt));*/


        return "转账成功";
    }
}
